package com.uinnova.product.eam.mvc;

import com.alibaba.fastjson.JSONObject;
import com.binary.framework.web.RemoteResult;
import com.uinnova.product.eam.service.MeasureEvaluateService;
import com.uinnova.product.eam.vo.MeasureEvaluateReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/measure/evaluate")
public class MeasureEvaluateController {

    @Autowired
    private MeasureEvaluateService measureEvaluateService;

    @PostMapping("/save")
    public RemoteResult save(@RequestBody MeasureEvaluateReq req) {
        measureEvaluateService.save(req);
        return new RemoteResult("success");
    }

    @PostMapping("/submit")
    public RemoteResult submit(@RequestBody String body) {
        JSONObject jsonObject = JSONObject.parseObject(body);
        String taskId = jsonObject.getString("taskId");
        measureEvaluateService.submit(taskId);
        return new RemoteResult("success");
    }

    @GetMapping("/statistic")
    public RemoteResult statistic(@RequestParam String processInstanceId, @RequestParam String businessKey) {
        measureEvaluateService.statistic(processInstanceId, businessKey);
        return new RemoteResult("success");
    }
}
